package com.atbeijing.D03;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 分布式转换算子
 */
public class Example1 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Integer> stream = env.fromElements(1, 2, 3, 4);

        stream
                .shuffle()//将原来1个并行度的数据随机发放到下游有两个并行度的print
                .print()
                .setParallelism(2);

//        stream
//                .rebalance()//平均分发
//                .print()
//                .setParallelism(2);
//
//        stream
//                .rescale()//平均分发,接收者任务数量是发送者任务数量的倍数时,操作将会效率更高
//                .print()
//                .setParallelism(2);

        env.execute();
    }



}
